package com.neuedu.his.service;

import com.neuedu.his.entity.MedicalRecord;
import com.neuedu.his.entity.Register;
import com.neuedu.his.mapper.MedicalRecordMapper;
import com.neuedu.his.mapper.RegisterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class MedicalRecordServiceImpl implements MedicalRecordService{

    @Autowired
    private MedicalRecordMapper MedDao;

    @Autowired
    private RegisterMapper RegDao;

    @Override
    public List<MedicalRecord> selectAll(MedicalRecord med) {
        return MedDao.selectAll(med);
    }

    @Override
    public MedicalRecord selectById(MedicalRecord med) {
        return MedDao.selectById(med);
    }

    @Override
    public int update(MedicalRecord med) {
        return MedDao.update(med);
    }

    @Override
    public int UpdateToStorage(MedicalRecord med) {
        med.setCasestate(1);
        return MedDao.update(med);
    }

    @Override
    public int UpdateToSub(MedicalRecord med) {
        med.setCasestate(2);
        return MedDao.update(med);
    }

    @Override
    public int UpdateToDef(MedicalRecord med) {
        med.setCasestate(3);
        return MedDao.update(med);
    }

    @Override
    public MedicalRecord selectByCaseNumber(MedicalRecord CaseNumber){
        return MedDao.selectByCaseNumber(CaseNumber);
    }

    @Override
    public MedicalRecord selectMedRecordByRealName(Register reg) {
        MedicalRecord med = new MedicalRecord();
        Register register = RegDao.selectRegisterByRealName(reg);
        med.setCasenumber(register.getCasenumber());
        return MedDao.selectByCaseNumber(med);
    }

    @Override
    public List<MedicalRecord> selectUndefinite(MedicalRecord med) {
        List<MedicalRecord> merge = new ArrayList<MedicalRecord>();
        List<MedicalRecord> l1 = new ArrayList<MedicalRecord>();
        List<MedicalRecord> l2 = new ArrayList<MedicalRecord>();
        l1 = MedDao.selectUndefiniteSto(med);
        l2 = MedDao.selectUndefiniteSub(med);
        merge.addAll(l1);
        merge.addAll(l2);
        return merge;
//        return MedDao.selectUndefinite(med);
    }

    @Override
    public List<MedicalRecord> selectDefinite(MedicalRecord med) {
        return MedDao.selectDefinite(med);
    }
}
